import requests, pandas as pd

# 1. 请求排行榜接口
url = 'https://api.bilibili.com/x/web-interface/ranking?rid=0&type=origin'
headers = {'User-Agent': 'Mozilla/5.0'}
data = requests.get(url, headers=headers).json()

# 2. 提取 100 条
records = [
    {'排名': idx + 1,
     '标题': item['title'],
     '播放量': item['play'],
     'UP主': item['author'],
     '封面': item['pic']}
    for idx, item in enumerate(data['data']['list'])
]

# 3. 保存 Excel
df = pd.DataFrame(records)
df.to_excel('bilibili_top100.xlsx', index=False)
print('已生成 bilibili_top100.xlsx，共', len(df), '条')